# ---------------------------------------
# --- PROFIBUS DP
# --- LinuxCNC HAL configuration file
# ------


# --- Load the pyprofibus HAL userspace module ---
#
# Parameters:
#  --loglevel LVL	: Change the log level.
#
#  --nice NICE		: Renice the process. -20 <= NICE <= 19.
#			  Default: Do not renice.
#
# The last parameter is the configuration file describing the PROFIBUS.
#
loadusr -Wn profibus pyprofibus-linuxcnc-hal pyprofibus.conf


# --- Enable the used master-to-slave pins ---
# MOSI = MasterOutputSlaveInput = Data flow from PB master to PB slave.
# All master-to-slave pins are deactivated by default.
# So all master-to-slave pins connected below, should be activated here by writing
# a '1' to the '.active' pin.
# Deactivated master-to-slave pins will not be forwarded from LinuxCNC to the PROFIBUS.
setp	profibus.slave.8.mosi.bit.0.0.active		1
setp	profibus.slave.8.mosi.bit.0.1.active		1
setp	profibus.slave.8.mosi.bit.1.0.active		1
setp	profibus.slave.8.mosi.bit.1.1.active		1
setp	profibus.slave.8.mosi.bit.1.2.active		1
setp	profibus.slave.8.mosi.bit.1.3.active		1
setp	profibus.slave.8.mosi.bit.1.4.active		1
setp	profibus.slave.8.mosi.float.4.active		1
setp	profibus.slave.8.mosi.float.8.active		1
setp	profibus.slave.8.mosi.float.12.active		1
setp	profibus.slave.8.mosi.u8.16.active		1
setp	profibus.slave.8.mosi.u16.18.active		1
setp	profibus.slave.8.mosi.s16.20.active		1
setp	profibus.slave.8.mosi.u31.22.active		1
setp	profibus.slave.8.mosi.s32.26.active		1

# --- Connect master-to-slave pins ---
# MOSI = MasterOutputSlaveInput = Data flow from PB master to PB slave.
net	heartbeat		=> profibus.slave.8.mosi.bit.0.0
net	estop-out-not		=> profibus.slave.8.mosi.bit.0.1
net	spindle-cw		=> profibus.slave.8.mosi.bit.1.0
net	spindle-ccw		=> profibus.slave.8.mosi.bit.1.1
net	xpos-cmd		=> profibus.slave.8.mosi.float.4
net	ypos-cmd		=> profibus.slave.8.mosi.float.8
net	zpos-cmd		=> profibus.slave.8.mosi.float.12

setp	profibus.slave.8.mosi.bit.1.2			1 # limit-x inverted dummy loopback
setp	profibus.slave.8.mosi.bit.1.3			1 # limit-y inverted dummy loopback
setp	profibus.slave.8.mosi.bit.1.4			1 # limit-z inverted dummy loopback
setp	profibus.slave.8.mosi.bit.1.5			0 # estop-in-not inverted dummy loopback


# --- Enable the used slave-to-master pins ---
# MISO = MasterInputSlaveOutput = Data flow from PB slave to PB master.
# All slave-to-master pins are deactivated by default.
# So all slave-to-master pins connected below, should be activated here by writing
# a '1' to the '.active' pin.
# Deactivated slave-to-master pins will not be forwarded from the PROFIBUS to LinuxCNC.
setp	profibus.slave.8.miso.bit.0.0.active		1
setp	profibus.slave.8.miso.bit.0.1.active		1
setp	profibus.slave.8.miso.bit.1.0.active		1
setp	profibus.slave.8.miso.bit.1.1.active		1
setp	profibus.slave.8.miso.bit.1.2.active		1
setp	profibus.slave.8.miso.bit.1.3.active		1
setp	profibus.slave.8.miso.bit.1.4.active		1
setp	profibus.slave.8.miso.bit.1.5.active		1
setp	profibus.slave.8.miso.float.4.active		1
setp	profibus.slave.8.miso.float.8.active		1
setp	profibus.slave.8.miso.float.12.active		1
setp	profibus.slave.8.miso.u8.16.active		1
setp	profibus.slave.8.miso.u16.18.active		1
setp	profibus.slave.8.miso.s16.20.active		1
setp	profibus.slave.8.miso.u31.22.active		1
setp	profibus.slave.8.miso.s32.26.active		1

# If the slave disconnects, then reset all slave-to-master pins to zero.
setp	profibus.slave.8.config.disconnect-clear-pins	1

# --- Connect slave-to-master pins ---
# MISO = MasterInputSlaveOutput = Data flow from PB slave to PB master.
net	limit-x			<= profibus.slave.8.miso.bit.1.2
net	limit-y			<= profibus.slave.8.miso.bit.1.3
net	limit-z			<= profibus.slave.8.miso.bit.1.4
net	estop-in-not		<= profibus.slave.8.miso.bit.1.5



# Always keep this at the end of this file.
# This will activate data transfer between pyprofibus and LinuxCNC.
setp	profibus.config.ready	1
